﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using System.IO;
using System.Web.Script.Serialization;
using System.Runtime.Serialization.Json;

namespace AllInOne.Common
{
    public static class JsonHelper
    {
        public static List<T> JSONStringToList<T>(this string JsonStr)
        {
            try
            {
                JavaScriptSerializer Serializer = new JavaScriptSerializer();
                List<T> objs = Serializer.Deserialize<List<T>>(JsonStr);
                return objs;
            }
            catch
            {
                return null;
            }
        }
        //public static T Deserialize<T>(string json)
        //{
        //    T obj = Activator.CreateInstance<T>();
        //    using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(json)))
        //    {
        //        DataContractJsonSerializer serializer = new DataContractJsonSerializer(obj.GetType());
        //        return (T)serializer.ReadObject(ms);
        //    }
        //}
    }
}





